package o;

import android.annotation.TargetApi;
import android.graphics.Point;
import android.media.MediaCodecInfo.AudioCapabilities;
import android.media.MediaCodecInfo.CodecCapabilities;
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCodecInfo.VideoCapabilities;
import android.util.Pair;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;

@TargetApi(16)
public final class ahe {
    public final boolean ʼ;
    public final boolean ʽ;
    @Nullable
    public final String ˊ;
    public final boolean ˋ;
    public final String ˎ;
    public final boolean ˏ;
    @Nullable
    public final CodecCapabilities ॱ;
    private final boolean ॱॱ;

    public static ahe ˏ(String str) {
        return new ahe(str, null, null, true, false, false);
    }

    public static ahe ॱ(String str, String str2, CodecCapabilities codecCapabilities, boolean z, boolean z2) {
        return new ahe(str, str2, codecCapabilities, false, z, z2);
    }

    private ahe(String str, @Nullable String str2, @Nullable CodecCapabilities codecCapabilities, boolean z, boolean z2, boolean z3) {
        boolean z4;
        boolean z5 = false;
        this.ˎ = (String) amm.ॱ(str);
        this.ˊ = str2;
        this.ॱ = codecCapabilities;
        this.ʼ = z;
        if (z2 || codecCapabilities == null || !ˋ(codecCapabilities)) {
            z4 = false;
        } else {
            z4 = true;
        }
        this.ˏ = z4;
        if (codecCapabilities == null || !ˏ(codecCapabilities)) {
            z4 = false;
        } else {
            z4 = true;
        }
        this.ˋ = z4;
        if (z3 || (codecCapabilities != null && ॱ(codecCapabilities))) {
            z5 = true;
        }
        this.ʽ = z5;
        this.ॱॱ = anb.ˋ(str2);
    }

    public String toString() {
        return this.ˎ;
    }

    public CodecProfileLevel[] ˎ() {
        return (this.ॱ == null || this.ॱ.profileLevels == null) ? new CodecProfileLevel[0] : this.ॱ.profileLevels;
    }

    public boolean ˊ(Format format) throws DecoderQueryException {
        boolean z = false;
        if (!ˋ(format.ˋ)) {
            return false;
        }
        if (!this.ॱॱ) {
            if (anr.ˋ >= 21) {
                if (format.ʼॱ != -1 && !ˊ(format.ʼॱ)) {
                    return false;
                }
                if (!(format.ॱˎ == -1 || ˏ(format.ॱˎ))) {
                    return false;
                }
            }
            return true;
        } else if (format.ͺ <= 0 || format.ˏॱ <= 0) {
            return true;
        } else {
            if (anr.ˋ >= 21) {
                return ˊ(format.ͺ, format.ˏॱ, (double) format.ॱˊ);
            }
            if (format.ͺ * format.ˏॱ <= MediaCodecUtil.ˏ()) {
                z = true;
            }
            if (z) {
                return z;
            }
            ˎ("legacyFrameSize, " + format.ͺ + "x" + format.ˏॱ);
            return z;
        }
    }

    public boolean ˋ(String str) {
        if (str == null || this.ˊ == null) {
            return true;
        }
        String ॱ = anb.ॱ(str);
        if (ॱ == null) {
            return true;
        }
        if (this.ˊ.equals(ॱ)) {
            Pair ˋ = MediaCodecUtil.ˋ(str);
            if (ˋ == null) {
                return true;
            }
            int intValue = ((Integer) ˋ.first).intValue();
            int intValue2 = ((Integer) ˋ.second).intValue();
            if (!this.ॱॱ && intValue != 42) {
                return true;
            }
            for (CodecProfileLevel codecProfileLevel : ˎ()) {
                if (codecProfileLevel.profile == intValue && codecProfileLevel.level >= intValue2) {
                    return true;
                }
            }
            ˎ("codec.profileLevel, " + str + ", " + ॱ);
            return false;
        }
        ˎ("codec.mime " + str + ", " + ॱ);
        return false;
    }

    public boolean ˋ(Format format) {
        if (this.ॱॱ) {
            return this.ˏ;
        }
        Pair ˋ = MediaCodecUtil.ˋ(format.ˋ);
        return ˋ != null && ((Integer) ˋ.first).intValue() == 42;
    }

    public boolean ॱ(Format format, Format format2, boolean z) {
        boolean z2 = true;
        if (this.ॱॱ) {
            boolean z3;
            if (format.ʽ.equals(format2.ʽ) && format.ˋॱ == format2.ˋॱ && ((this.ˏ || (format.ͺ == format2.ͺ && format.ˏॱ == format2.ˏॱ)) && ((!z && format2.ʻॱ == null) || anr.ˎ(format.ʻॱ, format2.ʻॱ)))) {
                z3 = true;
            } else {
                z3 = false;
            }
            return z3;
        } else if (!"audio/mp4a-latm".equals(this.ˊ) || !format.ʽ.equals(format2.ʽ) || format.ॱˎ != format2.ॱˎ || format.ʼॱ != format2.ʼॱ) {
            return false;
        } else {
            Pair ˋ = MediaCodecUtil.ˋ(format.ˋ);
            Pair ˋ2 = MediaCodecUtil.ˋ(format2.ˋ);
            if (ˋ == null || ˋ2 == null) {
                return false;
            }
            int intValue = ((Integer) ˋ.first).intValue();
            int intValue2 = ((Integer) ˋ2.first).intValue();
            if (!(intValue == 42 && intValue2 == 42)) {
                z2 = false;
            }
            return z2;
        }
    }

    @TargetApi(21)
    public boolean ˊ(int i, int i2, double d) {
        if (this.ॱ == null) {
            ˎ("sizeAndRate.caps");
            return false;
        }
        VideoCapabilities videoCapabilities = this.ॱ.getVideoCapabilities();
        if (videoCapabilities == null) {
            ˎ("sizeAndRate.vCaps");
            return false;
        }
        if (!ˎ(videoCapabilities, i, i2, d)) {
            if (i >= i2 || !ˎ(videoCapabilities, i2, i, d)) {
                ˎ("sizeAndRate.support, " + i + "x" + i2 + "x" + d);
                return false;
            }
            ॱ("sizeAndRate.rotated, " + i + "x" + i2 + "x" + d);
        }
        return true;
    }

    @TargetApi(21)
    public Point ॱ(int i, int i2) {
        if (this.ॱ == null) {
            ˎ("align.caps");
            return null;
        }
        VideoCapabilities videoCapabilities = this.ॱ.getVideoCapabilities();
        if (videoCapabilities == null) {
            ˎ("align.vCaps");
            return null;
        }
        int widthAlignment = videoCapabilities.getWidthAlignment();
        int heightAlignment = videoCapabilities.getHeightAlignment();
        return new Point(widthAlignment * anr.ˎ(i, widthAlignment), heightAlignment * anr.ˎ(i2, heightAlignment));
    }

    @TargetApi(21)
    public boolean ˊ(int i) {
        if (this.ॱ == null) {
            ˎ("sampleRate.caps");
            return false;
        }
        AudioCapabilities audioCapabilities = this.ॱ.getAudioCapabilities();
        if (audioCapabilities == null) {
            ˎ("sampleRate.aCaps");
            return false;
        } else if (audioCapabilities.isSampleRateSupported(i)) {
            return true;
        } else {
            ˎ("sampleRate.support, " + i);
            return false;
        }
    }

    @TargetApi(21)
    public boolean ˏ(int i) {
        if (this.ॱ == null) {
            ˎ("channelCount.caps");
            return false;
        }
        AudioCapabilities audioCapabilities = this.ॱ.getAudioCapabilities();
        if (audioCapabilities == null) {
            ˎ("channelCount.aCaps");
            return false;
        } else if (ˎ(this.ˎ, this.ˊ, audioCapabilities.getMaxInputChannelCount()) >= i) {
            return true;
        } else {
            ˎ("channelCount.support, " + i);
            return false;
        }
    }

    private void ˎ(String str) {
        amz.ˊ("MediaCodecInfo", "NoSupport [" + str + "] [" + this.ˎ + ", " + this.ˊ + "] [" + anr.ॱ + "]");
    }

    private void ॱ(String str) {
        amz.ˊ("MediaCodecInfo", "AssumedSupport [" + str + "] [" + this.ˎ + ", " + this.ˊ + "] [" + anr.ॱ + "]");
    }

    private static int ˎ(String str, String str2, int i) {
        if (i > 1) {
            return i;
        }
        if ((anr.ˋ >= 26 && i > 0) || "audio/mpeg".equals(str2) || "audio/3gpp".equals(str2) || "audio/amr-wb".equals(str2) || "audio/mp4a-latm".equals(str2) || "audio/vorbis".equals(str2) || "audio/opus".equals(str2) || "audio/raw".equals(str2) || "audio/flac".equals(str2) || "audio/g711-alaw".equals(str2) || "audio/g711-mlaw".equals(str2) || "audio/gsm".equals(str2)) {
            return i;
        }
        int i2;
        if ("audio/ac3".equals(str2)) {
            i2 = 6;
        } else if ("audio/eac3".equals(str2)) {
            i2 = 16;
        } else {
            i2 = 30;
        }
        amz.ˏ("MediaCodecInfo", "AssumedMaxChannelAdjustment: " + str + ", [" + i + " to " + i2 + "]");
        return i2;
    }

    private static boolean ˋ(CodecCapabilities codecCapabilities) {
        return anr.ˋ >= 19 && ˎ(codecCapabilities);
    }

    @TargetApi(19)
    private static boolean ˎ(CodecCapabilities codecCapabilities) {
        return codecCapabilities.isFeatureSupported("adaptive-playback");
    }

    private static boolean ˏ(CodecCapabilities codecCapabilities) {
        return anr.ˋ >= 21 && ˊ(codecCapabilities);
    }

    @TargetApi(21)
    private static boolean ˊ(CodecCapabilities codecCapabilities) {
        return codecCapabilities.isFeatureSupported("tunneled-playback");
    }

    private static boolean ॱ(CodecCapabilities codecCapabilities) {
        return anr.ˋ >= 21 && ʽ(codecCapabilities);
    }

    @TargetApi(21)
    private static boolean ʽ(CodecCapabilities codecCapabilities) {
        return codecCapabilities.isFeatureSupported("secure-playback");
    }

    @TargetApi(21)
    private static boolean ˎ(VideoCapabilities videoCapabilities, int i, int i2, double d) {
        if (d == -1.0d || d <= 0.0d) {
            return videoCapabilities.isSizeSupported(i, i2);
        }
        return videoCapabilities.areSizeAndRateSupported(i, i2, d);
    }
}
